#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

#define N 10

void worker()
{

}

int main()
{
    for(int i = 0; i < N; i++) 
    {
        pid_t id = fork();
        if(id == 0) 
        {
            worker();
            exit(i);
        }
    }

    for(int i = 0; i < N; i++)
    {
        int status = 0;
        pid_t rid = waitpid(-1, &status, 0);//pid>0,指定子进程,pid<0,匹配任意进程
        if(rid > 0)
        {
            printf("wait child %d success, exit_code: %d\n", rid, WEXITSTATUS(status));
        }
    }

    return 0;
}
